<div id="notify_sent_ildds" class="easyui-layout tab_a" fit="true">
    <div data-options="region:'center',border:false">
        <table id="notify_sent_list"></table>
        <div id="notifysentboxtoolbar" style="padding:5px;height:auto">
        	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="notify_add('新通告')">新建</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="notify_edit()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="notify_del()">删除</a>
            <label style=" float:right;">
                	<input id="notify_sent_search_key" class="notify_sent_search_form textbox" style="width:200px" type="text">
                	<a href="#" class="easyui-linkbutton notify_sent_search_form" iconCls="icon-search" plain="true" onclick="advanced_search('notify_sent','notify_sent_search_key')">搜索</a>
                <a id="notify_sent_advancedSearch" href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="advanced_search('notify_sent','高级')">高级</a>
            </label>
        </div>
	</div>
</div>
<script>
//发件箱数据构造方法，包括列表属性设置，字段设置，双击设置
$('#notify_sent_list').datagrid({
    url:'<?php echo base_url('notify/sentbox_data');?>',
	method:'post',
	singleSelect:true,
	selectOnCheck:false,
	pagination:true,
	pageSize:30,
	pageList:[30,50,100],
	fit:true,
	fitColumns:true,
	border:false,
	queryParams:{},
	sortName:'notify_id',
	sortOrder:'desc',
	toolbar:'#notifysentboxtoolbar',
    columns:[[
		{field:'id',checkbox:true},
		{field:'dept_name',title:'发布部门',width:30,align:'center'},	
		{field:'from_name',title:'发布人',width:16,align:'center'},	
		{field:'type_id',title:'类型',width:16,align:'center',
			formatter: function(value,row,index){
				if(value != 0){
					return "通知";
				}else{
					return "公告";
				}
			}
		},
        {field:'title',title:'标题',width:150},
		{field:'to_name',title:'发布范围',width:60,align:'center',
			formatter: function(value,row,index){
				return "<div title='"+value+"'>"+subStringCh(value,20,true)+'</div>';
			}
		},
		{field:'sendertime',title:'创建时间',width:20,align:'center',sortable:'true'},
		{field:'begin_date',title:'生效日期',width:20,align:'center',sortable:'true'},
		{field:'end_date',title:'终止日期',width:20,align:'center',sortable:'true'}
    ]],
	onDblClickRow:function(index,data){
		//var row=$('#notify_sent_list').datagrid('getSelected');
		//if(row){/**当前的tab 是否存在如果存在就 自动选择 否则 创建新的tab**/
		var title = (strlen(data.title) >10)?SetString(data.title,10)+'..':data.title;//如果标题超过10个字符，则截取10个字符加..
		var ef_id = 'ef_'+data.id; //拼接面板ID
		var ef_obj = $('#main-tab').find("#"+ef_id);//获取面板ID对象对象
			
		//var title = 'EF'+row.bodyid+':'+SetString(row.title,16);
		if (ef_obj.length>0){ 
			var tab_index = ef_obj.parent().index();//检查该对象的父元素在其父元素中的索引
			$('#main-tab').tabs('select', tab_index); 
		} else {
			/**添加一个tab标签**/
			$("#main-tab").tabs('add',{
				title: '通知公告:'+title,
				href: '<?php echo base_url();?>notify/contentbox/'+data.id,
				tabWidth:'180',
				selected: true,
				closable:true,
				onLoad:function(){ 
					//为面板添加详细标题属性 
					var item1 = $('.tabs-selected').find("span:first");
					$('#main-tab').find(item1).attr("title",data.title);
				}
			});
			
		}
		//}
	},
	onLoadSuccess:function(){
        var pager = $(this).datagrid('getPager');
        pager.pagination({
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
        });
    }
});

//新建通知公告
function notify_add(title){
	//$('#main-tab').tabs('close', '新邮件'); 
	
	if ($('#main-tab').tabs('exists', title)){
		$('#main-tab').tabs('select', title); 
	}else{
		//$('#main-tab').tabs('close', '新通告'); 
		
		$("#main-tab").tabs('add',{					
			title: title,
			href: '<?php echo base_url();?>notify/notify_add',
			selected: true,
			closable:true,
			iconCls:'icon-add'
		});	
	}
}

//编辑通知公告
function notify_edit(){
	var getobj = $('#notify_sent_list').datagrid("getChecked");
	var getid = [];

	$.each(getobj, function(index, item){
		getid.push(item.id);
	}); 

	if(getid.length == 0){
		$.messager.alert('提示','如需编辑，请选择要操作的行','warning');
	}else{
		//转发前先检查有无新通告标签面板，如果有先关闭
		if ($('#main-tab').tabs('exists', '新通告')){
			$('#main-tab').tabs('close', '新通告'); 
		}
		var row = $('#notify_sent_list').datagrid('getSelected');//返回第一个选中的行或者 null
		
		//然后新建添加'新邮件'面板，并根据提交参数判断是转发、重发、回复
		$("#main-tab").tabs('add',{
			title: '新通告',
			href: '<?php echo base_url();?>notify/notify_add/'+row.id,
			selected: true,
			closable:true,
			iconCls:'icon-add'
		});
	}
}

function notify_del(){
	var getobj = $('#notify_sent_list').datagrid("getChecked");
	var getid = [];

	$.each(getobj, function(index, item){
		getid.push(item.id);
	}); 
	
	if(getid.length == 0){
		$.messager.alert('提示','要删除，请选取要操作的行','warning');
	}else{
		$.messager.confirm('提示', '确定要删除选中的行吗?', function(r){
			if(r){
				$.post('<?php echo base_url();?>notify/notify_del',{getid:getid},function(result){
					if(result.success){
						$('#notify_sent_list').datagrid('reload');
					}else{
						$.messager.alert('错误',result.errorMsg,'error');
					}
				},'json');
			}
		});	
	}
}
</script>